package com.api.user.controller;

import com.api.core.annotation.PowerEnable;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.UserBankAccount;
import com.api.user.service.UserBankAccountService;
import io.swagger.annotations.*;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
* Created by wanghuiwen on 2021/03/30.
*/
@PowerEnable(name = "银行账号",url = "/user/bank/account")
@Api(value = "银行账号", tags = {"银行账号"})
@RestController
@RequestMapping("/user/bank/account")
public class UserBankAccountController extends Ctrl{
    @Resource
    private UserBankAccountService userBankAccountService;

    @ApiOperation(value = "银行账号添加", tags = {"银行账号"}, notes = "银行账号添加")
    @PostMapping(value="/add",name="银行账号添加")
    public Result add(@ApiParam UserBankAccount userBankAccount, Authentication authentication) {
        Long userId = getAuthUser(authentication).getId();
        userBankAccount.setUserId(userId);
        userBankAccountService.add(userBankAccount);
        return ResultGenerator.genSuccessResult();
    }



    @ApiOperation(value = "银行账号-用户列表", tags = {"银行账号"}, notes = "银行账号-用户列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "userId", dataType = "String", paramType = "query")
    })
    @PostMapping(value = "/account", name = "银行账号-用户列表")
    public Result account(@RequestParam Long userId) {
        List<Map<String, Object>> res = userBankAccountService.account(userId);
        return ResultGenerator.genSuccessResult(res);
    }
}
